<template>
  <div>
    <div style="margin-top: 10px;float: right;width: 30%;margin-bottom: 10px">
      <el-button  type="success"  round @click="append()">添加</el-button>
      <el-button  type="success"  round  @click="toggleSelection()">取消选择</el-button>
    </div>
    <el-table
      ref="multipleTable"
      :data="tableData"
      tooltip-effect="dark"
      style="width: 100%;height: 640px"
      @selection-change="handleSelectionChange">
      <el-table-column
        type="selection"
        width="55">
      </el-table-column>
      <el-table-column
        label="编号"
        width="120"
        prop="id"
      >
        <!--<template slot-scope="scope">{{ scope.row.date }}</template>-->
      </el-table-column>
      <el-table-column
        prop="namee"
        label="姓名"
        width="120">
      </el-table-column>
      <el-table-column
        prop="introduce"
        label="地址"
        show-overflow-tooltip>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        gid:'',
        tableData: [
          {
            namee:'',
            id:'',
            introduce:'',
            wid:''
          }
        ],
        multipleSelection: []
      }
    },
    mounted: function(){

      this.gid= this.$route.query.mallCode
      var user= JSON.parse(window.sessionStorage.getItem("user"));
      var ff=user.id
      axios.post('/workroom/findAllMember',{
        wid:ff,
        groupname:this.inputName,
      }).then((response) => {
        if( response.data != null){

          var e=response.data
          console.log(e)
          var data=[];
          let kk=0
          for(var c=0;c<e.length;c++){
            var ee=e[c];
            var obj={}
            var zz=ee.states
            if(zz==0){
            obj.namee=ee.namee
            obj.id=ee.id
            obj.introduce=ee.introduce
            obj.wid=ee.wid
            data[kk]=obj
            kk=kk+1
            }
            console.log(obj)}
          this. tableData=data
        }
        else{

        }
      })


    },
    methods: {
      toggleSelection(rows) {
        if (rows) {
          rows.forEach(row => {
            this.$refs.multipleTable.toggleRowSelection(row);
          });
        } else {
          this.$refs.multipleTable.clearSelection();
        }
      },
      append(){

        let gid=this.gid
        console.log(gid)
        let ff=this.multipleSelection
        var user= JSON.parse(window.sessionStorage.getItem("user"));
        var eee=user.id
        for(var c=0;c<ff.length;c++){

          var ee=ff[c]
          var uuu=ee.id
          console.log(uuu)
          axios.post('/workroom/insertGroupMember',{
            gid:gid,
            mid:uuu,
            wid:eee
          }).then((response) => {
            if( response.data .states==800){


              location.reload()
            }
            else{

            }
          })


        }

      },

      handleSelectionChange(val) {
        this.multipleSelection = val;



      }
    }
  }
</script>
